package com.xuexiang.xuidemo.page.uilts;

import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.components.Image;
import ohos.agp.components.Text;
import ohos.agp.utils.Color;
import ohos.agp.utils.LayoutAlignment;
import ohos.agp.utils.TextAlignment;
import ohos.app.Context;

import com.xuexiang.xuidemo.ResourceTable;
import com.xuexiang.xuidemo.page.base.BasePageAbilitySlice;
import com.xuexiang.xuidemo.page.base.Page;
import com.xuexiang.xuidemo.util.AppCfig;
import com.xuexiang.xuidemo.util.ToastUtil;
import com.xuexiang.xuidemo.util.SnackBarUtils;

/**
 * SnackBarUtils示例页面
 *
 * @since 2021-03-24
 */
@Page(name = "SnackBarUtils", action = "SnackBarUtils")
public class SnackBarUtilsAbilitySlice extends BasePageAbilitySlice implements Component.ClickedListener {
    @Override
    protected int getLayoutId() {
        return ResourceTable.Layout_ability_utils_snackbar;
    }

    private Context mContext;
    private Text text_title, text_title_bottom;

    private Image image_back;
    /**
     * 显示时长
     */
    private Button btn_short, btn_long, btn_indefinite, btn_length_custom;

    /**
     * 背景样式
     */
    private Button btn_info, btn_confirm, btn_warn, btn_danger;
    /**
     * 颜色设置
     */
    private Button btn_background_color, btn_message_color, btn_action_color;

    /**
     * 监听设置
     */
    private Button btn_action, btn_callback;

    /**
     * 文字对齐方式
     */
    private Button btn_default, btn_center, btn_right;

    /**
     * Sbackbar位置
     */
    private Button btn_gravity_bottom, btn_gravity_center, btn_gravity_top;

    /**
     * 其他用法
     */
    private Button btn_message_left_right_drawable, btn_add_view, btn_margin, btn_radius_stroke;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_snackbar);
        initComponent();
        initTitle();
        inintClickedListener();
    }

    private void initComponent() {
        mContext = SnackBarUtilsAbilitySlice.this;
        image_back = (Image) findComponentById(ResourceTable.Id_image_back);
        text_title = (Text) findComponentById(ResourceTable.Id_text_title);
        text_title_bottom = (Text) findComponentById(ResourceTable.Id_text_title_bottom);

        btn_short = (Button) findComponentById(ResourceTable.Id_btn_short);
        btn_long = (Button) findComponentById(ResourceTable.Id_btn_long);
        btn_indefinite = (Button) findComponentById(ResourceTable.Id_btn_indefinite);
        btn_length_custom = (Button) findComponentById(ResourceTable.Id_btn_length_custom);

        btn_info = (Button) findComponentById(ResourceTable.Id_btn_info);
        btn_confirm = (Button) findComponentById(ResourceTable.Id_btn_confirm);
        btn_warn = (Button) findComponentById(ResourceTable.Id_btn_warn);
        btn_danger = (Button) findComponentById(ResourceTable.Id_btn_danger);

        btn_background_color = (Button) findComponentById(ResourceTable.Id_btn_background_color);
        btn_message_color = (Button) findComponentById(ResourceTable.Id_btn_message_color);
        btn_action_color = (Button) findComponentById(ResourceTable.Id_btn_action_color);


        btn_action = (Button) findComponentById(ResourceTable.Id_btn_action);
        btn_callback = (Button) findComponentById(ResourceTable.Id_btn_callback);


        btn_default = (Button) findComponentById(ResourceTable.Id_btn_default);
        btn_center = (Button) findComponentById(ResourceTable.Id_btn_center);
        btn_right = (Button) findComponentById(ResourceTable.Id_btn_right);


        btn_gravity_bottom = (Button) findComponentById(ResourceTable.Id_btn_gravity_bottom);
        btn_gravity_center = (Button) findComponentById(ResourceTable.Id_btn_gravity_center);
        btn_gravity_top = (Button) findComponentById(ResourceTable.Id_btn_gravity_top);


        btn_message_left_right_drawable = (Button) findComponentById(ResourceTable.Id_btn_message_left_right_drawable);
        btn_add_view = (Button) findComponentById(ResourceTable.Id_btn_add_view);
        btn_margin = (Button) findComponentById(ResourceTable.Id_btn_margin);
        btn_radius_stroke = (Button) findComponentById(ResourceTable.Id_btn_radius_stroke);


    }

    private void initTitle() {
        text_title.setText("SnackBarUtils");
    }

    private void inintClickedListener() {
        image_back.setClickedListener(this);

        btn_short.setClickedListener(this);
        btn_long.setClickedListener(this);
        btn_indefinite.setClickedListener(this);
        btn_length_custom.setClickedListener(this);

        btn_info.setClickedListener(this);
        btn_confirm.setClickedListener(this);
        btn_warn.setClickedListener(this);
        btn_danger.setClickedListener(this);

        btn_background_color.setClickedListener(this);
        btn_message_color.setClickedListener(this);
        btn_action_color.setClickedListener(this);

        btn_action.setClickedListener(this);
        btn_callback.setClickedListener(this);

        btn_default.setClickedListener(this);
        btn_center.setClickedListener(this);
        btn_right.setClickedListener(this);

        btn_gravity_bottom.setClickedListener(this);
        btn_gravity_center.setClickedListener(this);
        btn_gravity_top.setClickedListener(this);

        btn_message_left_right_drawable.setClickedListener(this);
        btn_add_view.setClickedListener(this);
        btn_margin.setClickedListener(this);
        btn_radius_stroke.setClickedListener(this);

    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }

    @Override
    public void onClick(Component component) {
        switch (component.getId()) {
            case ResourceTable.Id_image_back:
                onBackPressed();
                break;
            case ResourceTable.Id_btn_short:
                SnackBarUtils.show(mContext, new Color(AppCfig.INFO),
                    Color.WHITE, Color.WHITE, AppCfig.LENGTH_SHORT,
                    LayoutAlignment.BOTTOM, TextAlignment.LEFT, "显示时长：短+info", null);
                break;
            case ResourceTable.Id_btn_long:
                SnackBarUtils.show(mContext, new Color(AppCfig.INFO),
                    Color.WHITE, Color.WHITE, AppCfig.LENGTH_LONG,
                    LayoutAlignment.BOTTOM, TextAlignment.LEFT, "显示时长：长+info", null);
                break;
            case ResourceTable.Id_btn_indefinite:
                SnackBarUtils.show(mContext, new Color(AppCfig.INFO),
                    Color.WHITE, Color.WHITE, AppCfig.SNACKBARTIME,
                    LayoutAlignment.BOTTOM, TextAlignment.LEFT, "显示时长：无限+info", "确定");

                break;
            case ResourceTable.Id_btn_length_custom:
                SnackBarUtils.show(mContext, new Color(AppCfig.INFO),
                    Color.WHITE, Color.WHITE, 3 * 1000,
                    LayoutAlignment.BOTTOM, TextAlignment.LEFT, "显示时长:自定义 3秒 + info", null);
                break;


            case ResourceTable.Id_btn_info:
                SnackBarUtils.show(mContext, new Color(AppCfig.INFO),
                    Color.WHITE, Color.WHITE, AppCfig.LENGTH_SHORT,
                    LayoutAlignment.BOTTOM, TextAlignment.LEFT, "背景样式：info", null);
                break;
            case ResourceTable.Id_btn_confirm:
                SnackBarUtils.show(mContext, new Color(AppCfig.CONFIRM),
                    Color.WHITE, Color.WHITE, AppCfig.LENGTH_SHORT,
                    LayoutAlignment.BOTTOM, TextAlignment.LEFT, "背景样式:confirm", null);
                break;
            case ResourceTable.Id_btn_warn:
                SnackBarUtils.show(mContext, new Color(AppCfig.WARNING),
                    Color.WHITE, Color.WHITE, AppCfig.LENGTH_SHORT,
                    LayoutAlignment.BOTTOM, TextAlignment.LEFT, "背景样式:warning", null);
                break;
            case ResourceTable.Id_btn_danger:
                SnackBarUtils.show(mContext, new Color(AppCfig.DANGER),
                    Color.WHITE, Color.WHITE, AppCfig.LENGTH_SHORT,
                    LayoutAlignment.BOTTOM, TextAlignment.LEFT, "背景样式:danger", null);
                break;

            case ResourceTable.Id_btn_background_color:
                SnackBarUtils.show(mContext, Color.GREEN,
                    Color.WHITE, Color.WHITE, AppCfig.LENGTH_SHORT,
                    LayoutAlignment.BOTTOM, TextAlignment.LEFT, "设置背景颜色: 绿色", null);
                break;
            case ResourceTable.Id_btn_message_color:
                SnackBarUtils.show(mContext, Color.BLACK,
                    Color.RED, Color.RED, AppCfig.LENGTH_SHORT,
                    LayoutAlignment.BOTTOM, TextAlignment.LEFT, "设置提示文字的颜色:红色", null);
                break;
            case ResourceTable.Id_btn_action_color:
                SnackBarUtils.show(mContext, Color.BLACK,
                    Color.WHITE, Color.WHITE, AppCfig.LENGTH_SHORT,
                    LayoutAlignment.BOTTOM, TextAlignment.LEFT, "设置按钮文字的颜色:白色", "确定");
                break;


            case ResourceTable.Id_btn_action:
                SnackBarUtils.show(mContext, Color.BLACK,
                    Color.WHITE, new Color(AppCfig.INFO), AppCfig.LENGTH_LONG,
                    LayoutAlignment.BOTTOM, TextAlignment.LEFT, "设置按钮文字及点击监听", "按钮文字");
                break;
            case ResourceTable.Id_btn_callback:
                ToastUtil.showToast(this, "onShown");
                getUITaskDispatcher().asyncDispatch(new Runnable() {
                    @Override
                    public void run() {
                        SnackBarUtils.show(mContext, Color.BLACK,
                            Color.WHITE, Color.WHITE, AppCfig.LENGTH_SHORT,
                            LayoutAlignment.BOTTOM, TextAlignment.LEFT, "设置显示及隐藏监听", null);
                    }
                });
                ToastUtil.showToast(this, "onDismissed!");
                break;
            case ResourceTable.Id_btn_default:
                SnackBarUtils.show(mContext, Color.BLACK,
                    Color.WHITE, Color.WHITE, AppCfig.LENGTH_SHORT,
                    LayoutAlignment.BOTTOM, TextAlignment.LEFT, "文字位置:默认", null);
                break;
            case ResourceTable.Id_btn_center:
                SnackBarUtils.show(mContext, Color.BLACK,
                    Color.WHITE, Color.WHITE, AppCfig.LENGTH_SHORT,
                    LayoutAlignment.BOTTOM, TextAlignment.CENTER, "文字位置:居中", null);
                break;
            case ResourceTable.Id_btn_right:
                SnackBarUtils.show(mContext, Color.BLACK,
                    Color.WHITE, Color.WHITE, AppCfig.LENGTH_SHORT,
                    LayoutAlignment.BOTTOM, TextAlignment.RIGHT, "文字位置:居右", null);
                break;

            case ResourceTable.Id_btn_gravity_bottom:
                SnackBarUtils.show(mContext, Color.BLACK,
                    Color.WHITE, Color.WHITE, AppCfig.LENGTH_SHORT,
                    LayoutAlignment.BOTTOM, TextAlignment.LEFT, "Snackbar位置:默认", null);
                break;
            case ResourceTable.Id_btn_gravity_center:
                SnackBarUtils.show(mContext, Color.BLACK,
                    Color.WHITE, Color.WHITE, AppCfig.LENGTH_SHORT,
                    LayoutAlignment.CENTER, TextAlignment.LEFT, "Snackbar位置:居中", null);
                break;
            case ResourceTable.Id_btn_gravity_top:
                SnackBarUtils.show(mContext, Color.BLACK,
                    Color.WHITE, Color.WHITE, AppCfig.LENGTH_SHORT,
                    LayoutAlignment.TOP, TextAlignment.LEFT, "Snackbar位置:顶部", null);
                break;
            case ResourceTable.Id_btn_message_left_right_drawable:
                SnackBarUtils.show(mContext, "设置文字位置左右两侧图片",
                    Color.BLACK, ResourceTable.Media_icon_avatar1, ResourceTable.Media_icon_avatar2);
                break;
            case ResourceTable.Id_btn_add_view:
                SnackBarUtils.show(mContext, "向Snackbar布局中添加View", ResourceTable.Media_ic_xul);
                break;
            case ResourceTable.Id_btn_margin:
                SnackBarUtils.show(mContext, Color.BLACK,
                    Color.WHITE, Color.WHITE, AppCfig.LENGTH_SHORT,
                    LayoutAlignment.BOTTOM, TextAlignment.LEFT, "设置Snackbar布局的外边距", null);
                break;
            case ResourceTable.Id_btn_radius_stroke:
                SnackBarUtils.show(mContext, Color.BLACK,
                    LayoutAlignment.BOTTOM, TextAlignment.LEFT, "设置圆角半径值及边框");
                break;
        }
    }
}

